<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- public quote -->
<%@include file="/jsp/comm_css_include.jsp"%>
<!-- zTreeStyle.css -->
<link rel="stylesheet" type="text/css" href="${basePath}/css/zTreeStyle/zTreeStyle/zTreeStyle.css">
<!doctype html>
<html>
<head>
<style type="text/css">
.gray-bg {
	background-color: #fff;
}
</style>
</head>
<body class="gray-bg">
	<form class="form-horizontal" id="commentForm">
		<div class="marginsfive">
			<div class="padding-nono">
				<table cellpadding="0" cellspacing="0" border="0"
					class="buyinfor-table">
					<tr>
						<td align="right"><label class="control-label np">经销商名称：</label>
						</td>
						<td><input id="dealerName" name="dealerName" minlength="1" maxlength="64" type="text" class="form-control" required="" placeholder="请输入经销商名称(必填)"></td>
						<td align="right"><label class="control-label np">经销商助记码：</label> </td>
						<td><input id="dealerMnemonicCode" name="dealerMnemonicCode" minlength="1" maxlength="64" type="text" class="form-control"  placeholder="请输入经销商助记码"></td>
					</tr>
					<tr>
						<td align="right"><label class="control-label np">经销商类别：</label> </td>
						<td><select id="dealerType" name="dealerType" class="form-control"></select></td>	
						<td align="right"><label class="control-label np">经销商等级：</label>
						<td><mytag:selectTag id="dealerLevel" name="dealerLevel" map="${dealerLevel }" others="class=\"select-control\"" /></td>
					</tr>
					
					<tr>
						<td align="right"><label class="control-label np">协议签署时间：</label> </td>
						<td><input id="dateSign" name="dateSign" class="laydate-icon form-control" type="text" class="form-control" placeholder="协议签署时间" /></td>	
						<td align="right"><label class="control-label np">协议到期时间：</label>
						<td><input id="dateExpire" name="dateExpire"   type="text" class="laydate-icon form-control" placeholder="协议到期时间" /></td>
					</tr>
					
					<tr>
						<td align="right"><label class="control-label np">所属机构：</label> </td>
						<td>
							<input id="unitCode" name="unitCode" type="hidden" />
							<input id="unitId" name="unitId" type="hidden" />
							<input id="unitName" name="unitName" readonly="readonly" required="required" class="form-control smalliconcur smallicon" onclick="choOrg();" type="text"  placeholder="所属机构(必填)" />
						</td>	
					</tr>
				</table>
			</div>
	
			<div class="business-manwife">附加信息</div>
			<div class="padding-nono">
				<table cellpadding="0" cellspacing="0" border="0"
					class="buyinfor-table">
					<tr>
						<td align="right" class="td-width"><label
							class="control-label np">所在省：</label></td>
						<td><mytag:selectTag id="province" name="dealerProvince"
								map="${provinces}" others="class=\"select-control\"" /></td>
						<td align="right"><label class="control-label np">所在市：</label>
						</td>
						<td style="width: 200px;"><mytag:selectTag id="city"
								name="dealerCity" map="${cities }"
								others="class=\"select-control\"" /></td>
					</tr>
					<tr>
						<td align="right"><label class="control-label np">详细地址：</label>
						</td>
						<td colspan="3"><input id="addr" name="addr" minlength="1"
							maxlength="128" type="text" class="form-control"
							aria-required="true" placeholder="请输入详细地址" /></td>
					</tr>
					<tr>
						<td align="right"><label class="control-label np">经营范围：</label>
						</td>
						<td colspan="3"><input id="scopeManage" name="scopeManage"
							minlength="1" maxlength="128" type="text" class="form-control"
							aria-required="true" placeholder="请输入经营范围" /></td>
					</tr>
					<tr>
						<td align="right"><label class="control-label np">社会信用代码：</label>
						</td>
						<td><input id="codeCompany" name="codeCompany" minlength="1"
							maxlength="64" type="text" class="form-control"
							aria-required="true" placeholder="请输入社会信用代码"></td>
					</tr>
					<tr>
						<td align="right" valign="top"><label class="control-label np">备注：</label>
						</td>
						<td colspan="3"><textarea id="remarks" name="remarks"
								cols="20" rows="3" type="text" class="form-control"
								aria-required="true" placeholder="请输入备注"></textarea></td>
					</tr>
				</table>
			</div>
			<div class="business-manwife">合作信息</div>
			<div class="padding-nono">
				<table cellpadding="0" cellspacing="0" border="0"
					class="buyinfor-table">
					<tr>
						<td align="right" class="td-width"><label
							class="control-label np">联系人：</label></td>
						<td><input id="contactPerson" name="contactPerson"
							minlength="1" maxlength="64" type="text" class="form-control"
							 aria-required="true" placeholder="请输入联系人 " />
						</td>
						<td align="right"><label class="control-label np">联系人手机：</label>
						</td>
						<td style="width: 200px;"><input id="tel" name="tel"
							minlength="1" maxlength="64" type="text" class="form-control"
							 aria-required="true" placeholder="联系人手机 " />
						</td>
					</tr>
					<tr>
						<td align="right"><label class="control-label np">收款人职位：</label>
						</td>
						<td><input id="rank" name="rank" minlength="1" maxlength="64"
							type="text" class="form-control" 
							aria-required="true" placeholder="收款人职位 " /></td>
						<td align="right"><label class="control-label np">账号：</label>
						</td>
						<td><input id="bankNo" name="bankNo" minlength="1"
							maxlength="64" type="text" class="form-control"
							  aria-required="true" placeholder="账号 " />
						</td>
					</tr>
					<tr>
						<td align="right"><label class="control-label np">开户行：</label>
						</td>
						<td><input id="bank" name="bank" minlength="1" maxlength="64"
							type="text" class="form-control" 
							aria-required="true" placeholder="开户行 " /></td>
						<td align="right"><label class="control-label np">户名：</label>
						</td>
						<td><input id="accountName" name="accountName" minlength="1"
							maxlength="64" type="text" class="form-control"
							 aria-required="true" placeholder="户名 " />
						</td>
					</tr>
					<tr>
						<td align="right" valign="top"><label class="control-label np">合作模式：</label>
						</td>
						<td colspan="3"><textarea id="remarkCooperation"
								name="remarkCooperation" cols="20" rows="3" type="text"
								class="form-control" aria-required="true" placeholder="请输入备注"></textarea>
						</td>
					</tr>
				</table>
			</div>
		</div>	
		<div class="div-fixedb">
			<table cellpadding="0" cellspacing="0" border="0" width="100%" style="bottom: 0px; margin-bottom: 0px;">
				<tr>
					<td width="100%" align="center">
						<div class="ibox-content" style="clear: none; border: none;">
							<button type="button" class="btn dpbtn_green" onclick="save();">确定</button>
							<button type="button" class="btn dpbtn_red" onclick="cancel();">取消</button>
						</div>
					</td>
				</tr>
			</table>
		</div>	
	</form>


	<!-- public quote -->
	<%@include file="/jsp/comm_js_include.jsp"%>

	<!-- public quote -->
	<%@include file="/jsp/comm_js_region_include.jsp"%>

	<!-- layerDate plugin javascript -->
	<script src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>
	
	<!--zTreeStyle.js-->
	<script type="text/javascript" src="${basePath}/js/zTreeStyle/jquery.ztree.core.js" charset="utf-8"></script>
	<script type="text/javascript" src="${basePath}/js/zTreeStyle/jquery.ztree.excheck.js" charset="utf-8"></script>

	<script type="text/javascript">
	jQuery(function($) {  
    	getData();
    	
    	laydate({
	        elem: '#dateSign', 
	        event: 'focus' 
	    });
    	laydate({
	        elem: '#dateExpire', 
	        event: 'focus' 
	    });
    	
    });
	
    function getData(){
    	$.dpAjax({
	    	url:'${basePath}/DataDictionaryController/getEnableList',
 			data:{
 				"parentValue":"Dealer_Type"
 			},
 			success: function(datas){
 				  var result = datas.result.rows;
				  var programme_sel=[];
			      for(var i=0;i<result.length;i++){
			          var programme = result[i];
			          programme_sel.push('<option value="'+programme.value+'">'+programme.name+'</option>')
			      }
			     $("#dealerType").html(programme_sel.join(' '));
				 return;
             }
	    });
    }
	
    var orgLayer;
 	  
 	function choOrg(){
    	$.dpAjax({
    		url:'${basePath}/BaseBusiUnitController/list',
   			data:{dpStatus:1},
   			show:false,
   			success: function(datas){
   				var content = '<div class="ibox-content" style="height: 380px;border: 1px solid #F5F5F6; overflow:auto;overflow-x: hidden;">'
					+ '	<div id="orgtreeDemo" class="ztree">&nbsp;</div>'
					+ '</div>'
					+ '<div class="ibox-content">'
					+ '<button class="btn dpbtn_green" type="button" onclick="confirmOrg();">确定</button>&nbsp;'
					+ '<button class="btn dpbtn_red" type="button" onclick="cancelOrg();">取消</button>'
					+ '</div>';
		
				orgLayer = layer.open({
			    	  title:'分配关联业务员',
			    	  type: 1,
			    	  area: ['600px', '500px'], //宽高
			    	  content: content
			    });
		    	
			    var setting = {
					check: {
						enable: false
					},
					data: {
						simpleData: {
							enable: true
						},
					}
			    };			
   				
   			  var  arr = [];
			  var d = datas.result.rows;
			  for(var i=0;i<d.length;i++)
			  {  
				  var r = d[i];
				  var objs = {};
				  objs.id = r.replaceId;
				  objs.pId = r.parentId;
				  objs.orgCode=r.orgCode;
				  objs.name = r.orgName;
				  objs.parentCode=r.parentCode;
				  if(r.replaceId == 1){
         		  	objs.open = true;
				  } else {
					objs.open = false; 
				  }
				  arr.push(objs);
			  }  
			  $.fn.zTree.init($("#orgtreeDemo"), setting, arr);
			  return;
            }
    	});
    }
 	
 	var confirmOrg = function(){
		var treeObj = $.fn.zTree.getZTreeObj("orgtreeDemo");
		var nodes = treeObj.getSelectedNodes();
		var treeNode = nodes[0];
        if(treeNode.id == 1) {
        	layer.msg('无法选择顶级机构',{icon:7});
        	return;
        }
        $("#unitId").val(treeNode.id);
        $("#unitCode").val(treeNode.orgCode);
        $('#unitName').val(treeNode.name);
        layer.closeAll();
    }
	
 	var cancel = function(){
		parent.layer.closeAll();
	}
 	
 	var cancelOrg = function(){
		layer.close(orgLayer);
	}
 	
    var save = function () {
        var validstatus = $("#commentForm").valid();
        if (!validstatus) {
        	layer.msg("有验证未通过，请检查！", {icon: 5});
        	return;
        }
        var data = $('#commentForm').serialize();
        $.dpAjax({
            url: '${basePath}/YwShouLiController/diepuDealer',
            data: data,
            success: function (datas) {
            	 layer.msg("添加执行成功！", {icon: 6});
                 parent.layer.close(parent.addlayer);
                 return;
            }
        });
    }
    
    $(function(){	
        $("#commentForm").validate({
        	rules:{
        		tel:{
        			mobile:true
        		}
        	},
            //重写showErrors
            showErrors: function (errorMap, errorList) {
                
                $.each(errorList, function (i, v) {
                    layer.tips(v.message, v.element, { time: 1500 });
                    return false;
                });  
            },
            /* 失去焦点时验证 */
            onfocusout: function(element) { $(element).valid(); },
            /*  键盘抬起不验证 */
            onkeyup:false,
        });
    });  
</script>
</body>
</html>
